| Conditions | 1 |
| Paths | 2 |
| Total Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 64 | PassmanImporter.EnPassTXT.readFile = function (file_data) { |
||
| 65 | var mapper = { |
||
| 66 | 'Title': 'label', |
||
| 67 | 'Username': 'username', |
||
| 68 | 'Password': 'password', |
||
| 69 | 'Email': 'email', |
||
| 70 | 'Url': 'url', |
||
| 71 | 'Note': 'description' |
||
| 72 | }; |
||
| 73 | |||
| 74 | var secret_fields = ['cvc', 'pin', 'security answer']; |
||
| 75 | |||
| 76 | return new C_Promise(function(){ |
||
| 77 | var credential_list = []; |
||
| 78 | var credentials = parseEnpass(file_data); |
||
| 79 | for (var i = 0; i < credentials.length; i++) { |
||
| 80 | var enpass_credential = credentials[i]; |
||
| 81 | var new_credential = PassmanImporter.newCredential(); |
||
| 82 | for(var key in enpass_credential){ |
||
| 83 | if(!enpass_credential.hasOwnProperty(key)){ |
||
| 84 | continue; |
||
| 85 | } |
||
| 86 | |||
| 87 | if(mapper.hasOwnProperty(key)){ |
||
| 88 | var prop = mapper[key]; |
||
| 89 | new_credential[prop] = enpass_credential[key]; |
||
| 90 | } else { |
||
| 91 | var isSecret = (secret_fields.indexOf(key.toLowerCase()) !== -1) ? 1 : 0; |
||
| 92 | new_credential.custom_fields.push({ |
||
| 93 | 'label': key, |
||
| 94 | 'value': enpass_credential[key], |
||
| 95 | 'secret': isSecret |
||
| 96 | }) |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | if(enpass_credential.hasOwnProperty('TOTP')){ |
||
| 101 | new_credential.otp.secret = enpass_credential['TOTP']; |
||
| 102 | } |
||
| 103 | |||
| 104 | var progress = { |
||
| 105 | percent: i/credentials.length*100, |
||
| 106 | loaded: i, |
||
| 107 | total: credentials.length |
||
| 108 | }; |
||
| 109 | |||
| 110 | credential_list.push(new_credential); |
||
| 111 | this.call_progress(progress); |
||
| 112 | } |
||
| 113 | this.call_then(credential_list); |
||
| 114 | }); |
||
| 115 | }; |
||
| 116 | })(window, $, PassmanImporter); |